<?php
    include '../data/material_dal.php';
    include_once '../entity/material_entity.php';

    class MaterialMng
    {
        function update($materialEntity)
        {
            $materialDAL = new MaterialDAL();
            return $materialDAL->update($materialEntity->id, $materialEntity->rfqID, $materialEntity->type, $materialEntity->qty, $materialEntity->ciNumber, $materialEntity->tradeName, $materialEntity->polymers, $materialEntity->processing, $materialEntity->application, $materialEntity->specialEffect, $materialEntity->specialEquipment, $materialEntity->inTime, $materialEntity->inUser);
     
        }

        function get($id)
        {
            $where = "id = " . $id;
            $materialDAL = new MaterialDAL();
            if ($result = $materialDAL->get($where)) {
                $row = $result->fetch_assoc();
                $materialEntity = new MaterialEntity();
                foreach ($row as $key => $value) {
                    $materialEntity->$key = $value;
                }
                return $materialEntity;
            } else {
                return false;
            }
        }

        function getAll($start, $pageSize, $sortField, $sortDirection)
        {
            $orderBy = "ORDER BY " . $sortField . " " . $sortDirection . " LIMIT " . $start . ", " . ($pageSize * ($start + 1));
            $materialDAL = new MaterialDAL();
            if ($result = $materialDAL->getAll($orderBy)) {
                while ($row = $result->fetch_array()) {
                    $materialList[] = $row;
                }
                return $materialList;
            } else {
                return false;
            }
        }

        function delete($id)
        {
            $materialDAL = new MaterialDAL();
            return $materialDAL->delete($id);
        }
    }
?>
